//
//  YDYHomeViewController.m
//  DY_Bilibili
//
//  Created by 杨德勇 on 2016/10/8.
//  Copyright © 2016年 杨德勇. All rights reserved.
//

#import "YDYHomeViewController.h"
#import "YDYLiveViewController.h"
#import "YDYLivePlayerController.h"
#import "YDYLive.h"
@interface YDYHomeViewController ()
//顶部按钮下方横线的中心x约束
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *lineViewCenterLayout;
//下划线
@property (weak, nonatomic) IBOutlet UIView *lineView;
//滑动
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

@end

@implementation YDYHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;
    [self setupScrollview];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(presentLivePlayerController:) name:ydy_presentLivePlayerNotification object:nil];


}
-(void)setupScrollview{
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.pagingEnabled = YES;
    self.scrollView.contentSize = CGSizeMake(YDYScreenSize.width * 3, 0);
    
    //这一行如果不写，tabview出现的瞬间，self.view就自动把宽度变为0，tableview就不能滑动了
    self.scrollView.autoresizesSubviews = NO;
    
    YDYLiveViewController *liveController = [[YDYLiveViewController alloc]init];
    UINavigationController *liveNav  = [[UINavigationController alloc]initWithRootViewController:liveController];
    [self addChildViewController:liveNav];
    
    
    
    liveController.view.frame = CGRectMake(0, 0, YDYScreenSize.width, YDYScreenSize.height);
    [self.scrollView addSubview:liveController.view];
//   
    
    
}


#pragma mark -
#pragma mark -顶端的三个按钮的点击事件
- (IBAction)live:(UIButton *)button {
    [self moveLineView:button];
    
    
}
- (IBAction)recommend:(UIButton *)button {
    [self moveLineView:button];
}

- (IBAction)bankumi:(UIButton *)button {
    [self moveLineView:button];
}


#pragma mark -
#pragma mark -private
-(void)moveLineView:(UIButton *)btn{
    
    [UIView animateWithDuration:0.25 animations:^{
        self.lineViewCenterLayout.constant = btn.frame.origin.x;
       
        [self.view layoutIfNeeded];
    }];
    
    
}
-(void)presentLivePlayerController:(NSNotification *)noti{
    if (noti.object == nil)return;
    
    YDYLive *live = noti.object;
    [YDYLivePlayerController playLiveWithURL:[NSURL URLWithString:live.playurl] title:live.title inController:self.navigationController];
    
//    YDYLog(@"%@",live.title);
}
-(void)dealloc{
    YDYLog(@"fuck");
}

@end
